package com.modong.jianjian.view.activity.contacts

import com.metaapp.demo.bean.SearchDataBean
import com.metaapp.demo.net.ApiObserver
import com.metaapp.demo.net.DataManager
import com.modong.jianjian.base.BasePresenter

class MainPresenter : BasePresenter<MainContract.View>(), MainContract.Presenter {

    private var sn = 0
    private var pn = 30

    /**
     * 获取检索数据
     */
    override fun getSearchPic(searchContent: String) {
        val maps = HashMap<String, Any>()
        maps.put("q", searchContent)
        maps.put("sn", sn)
        maps.put("pn", pn)
        DataManager.remoteRepository().getSearchPic(maps)
            .subscribe(object : ApiObserver<SearchDataBean>(this@MainPresenter) {
                override fun doOnSuccess(data: SearchDataBean, msg: String?) {
                    //页码大于0 则为加载更多
                    if (sn > 0) {
                        mView?.onLoadmoreSuccess(data)
                    } else {
                        mView?.onSearchPicSuccess(data)
                    }

                }
            })
    }

    /**
     * 加载更多
     */
    override fun loadMoreData(searchContent: String) {
        sn++
        getSearchPic(searchContent)
    }


}